﻿using System;
using System.Diagnostics;
using Microsoft.Win32;
using System.Windows.Forms;

namespace nb.development.csmediamanager
{
    static class FileShellExtension
    {
        public static void Register()
        {
            string menuCommand = string.Format("\"{0}\" \"-Upload\" \"%L\"", Application.ExecutablePath);
            string regPath = string.Format(@"{0}\shell\{1}", "*", "CSMediaManShell");
            Registry.ClassesRoot.CreateSubKey(regPath).SetValue(null, "Upload to...");
            Registry.ClassesRoot.CreateSubKey(string.Format(@"{0}\command", regPath)).SetValue(null, menuCommand);
            regPath = string.Format(@"{0}\shell\{1}", "Directory", "CSMediaManShell");
            menuCommand = string.Format("\"{0}\" \"-UploadDirectory\" \"%L\"", Application.ExecutablePath);
            Registry.ClassesRoot.CreateSubKey(regPath).SetValue(null, "Upload contents to...");
            Registry.ClassesRoot.CreateSubKey(string.Format(@"{0}\command", regPath)).SetValue(null, menuCommand);
        }

        public static bool isRegistered()
        {
            if (Registry.ClassesRoot.OpenSubKey(string.Format(@"{0}\shell\{1}", "*", "CSMediaManShell")) != null) return true;
            return false;
        }

        public static void Unregister()
        {
            string regPath = string.Format(@"{0}\shell\{1}", "*", "CSMediaManShell");
            Registry.ClassesRoot.DeleteSubKeyTree(regPath);
            regPath = string.Format(@"{0}\shell\{1}", "Directory", "CSMediaManShell");
            Registry.ClassesRoot.DeleteSubKeyTree(regPath);
        }
    }
}
